import 'package:flutter/material.dart';
import 'package:wallet_utils/color.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class Themes {

  static final mainTheme = ThemeData(
    ///用于导航栏、FloatingActionButton等控件
    primarySwatch: createMaterialColor(ColorManager.colorF65247),

    ///配置应用程序为亮色或者暗色
    brightness: Brightness.light,

    ///配置应用程序主背景色
    primaryColor: ColorManager.colorF65247,

    ///配置应用的前景色和其他控件的颜色  例如switch控件 radio控件  和输入框光标颜色和文本输入框默认下划线颜色
    colorScheme:
        ColorScheme.fromSwatch().copyWith(secondary: ColorManager.colorF65247),

    ///设置scaffold背景色
    scaffoldBackgroundColor: ColorManager.colorF9F9F9,
    appBarTheme: AppBarTheme(

        ///设置appbar背景色
        backgroundColor: ColorManager.colorFFFFFF,
        iconTheme: IconThemeData(

            ///配置appbar上icon图标颜色
            color: ColorManager.colorF65247,

            ///配置大小
            size: 22,

            ///配置透明度
            opacity: 1),
        actionsIconTheme: IconThemeData(

            ///配置appbar上action图标颜色
            color: ColorManager.colorF65247,

            ///配置大小
            size: 22,

            ///配置透明度
            opacity: 1),
        toolbarTextStyle:
            TextStyle(color: ColorManager.colorFFFFFF, fontSize: 30)),
    elevatedButtonTheme: ElevatedButtonThemeData(
        style: ButtonStyle(
        elevation: MaterialStateProperty.all(0), //阴影
      foregroundColor: MaterialStateProperty.resolveWith(
        (states) {
          if (states.contains(MaterialState.focused) &&
              !states.contains(MaterialState.pressed)) {
            //获取焦点时的颜色
            return ColorManager.colorF65247;
          } else if (states.contains(MaterialState.pressed)) {
            //按下时的颜色
            return ColorManager.colorF65247;
          }
          //默认状态使用灰色
          return ColorManager.colorFBB9B5;
        },
      ),

      //背景颜色
      backgroundColor: MaterialStateProperty.resolveWith((states) {
        //设置按下时的背景颜色
        if (states.contains(MaterialState.pressed)) {
          return ColorManager.colorF65247;
        } else if (states.contains(MaterialState.disabled)) {
          return ColorManager.colorFBB9B5;
        }
        //默认不使用背景颜色
        return ColorManager.colorF65247;
      }),
      //设置水波纹颜色
      // overlayColor: MaterialStateProperty.all(ColorManager.colorF65247),
    )),
    textButtonTheme: TextButtonThemeData(
      style: ButtonStyle(
        foregroundColor: MaterialStateProperty.resolveWith(
          (states) {
            if (states.contains(MaterialState.focused) &&
                !states.contains(MaterialState.pressed)) {
              //获取焦点时的颜色
              return ColorManager.colorF65247;
            } else if (states.contains(MaterialState.pressed)) {
              //按下时的颜色
              return ColorManager.colorF65247;
            }
            //默认状态使用灰色
            return ColorManager.colorFBB9B5;
          },
        ),

        //背景颜色
        backgroundColor: MaterialStateProperty.resolveWith((states) {
          //设置按下时的背景颜色
          if (states.contains(MaterialState.pressed)) {
            return ColorManager.colorF65247;
          } else if (states.contains(MaterialState.disabled)) {
            return ColorManager.colorFBB9B5;
          }
          //默认不使用背景颜色
          return ColorManager.colorF65247;
        }),
        //设置水波纹颜色
        // overlayColor: MaterialStateProperty.all(ColorManager.colorF65247),
      ),
    ),
    // 按钮颜色
    buttonTheme: ButtonThemeData(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(5.0),
      ),
      textTheme: ButtonTextTheme.normal,

      ///button使用的背景颜色
      buttonColor: ColorManager.colorF65247,

      ///button不可点击时的颜色
      disabledColor: ColorManager.colorFBB9B5,

      ///点击时高亮的颜色
      // highlightColor: ColorManager.color_4D4D4D,
      ///轻触时水波纹的颜色
      splashColor: ColorManager.colorFBB9B5,

      ///获取焦点时的颜色
      // focusColor: ColorManager.color_F65247,
    ),
  );

  static final black = ThemeData.light().copyWith(
      scaffoldBackgroundColor: Colors.black,
      appBarTheme: const AppBarTheme(
          backgroundColor: Colors.black,
          toolbarTextStyle: TextStyle(color: Colors.white, fontSize: 30)),
      elevatedButtonTheme: ElevatedButtonThemeData(
          style: ButtonStyle(
              backgroundColor: MaterialStateProperty.all(Colors.brown))));

  static MaterialColor createMaterialColor(Color color) {
    List strengths = <double>[.05];
    Map<int, Color> swatch = <int, Color>{};
    final int r = color.red, g = color.green, b = color.blue;

    for (int i = 1; i < 10; i++) {
      strengths.add(0.1 * i);
    }
    strengths.forEach((strength) {
      final double ds = 0.5 - strength;
      swatch[(strength * 1000).round()] = Color.fromRGBO(
        r + ((ds < 0 ? r : (255 - r)) * ds).round(),
        g + ((ds < 0 ? g : (255 - g)) * ds).round(),
        b + ((ds < 0 ? b : (255 - b)) * ds).round(),
        1,
      );
    });
    return MaterialColor(color.value, swatch);
  }
}
